import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/",
    name: "/",
    redirect: "/construct",
  },

  {
    path: "/construct",
    component: () => import("@/views/construct/index.vue"),
    meta: {
      title: "建设总览",
      hidden: true,
      keepAlive: true,
    },
  },
  {
    path: "/project",
    component: () => import("@/views/project/index.vue"),
    meta: {
      title: "项目管理",
      hidden: true,
      keepAlive: true,
    },
  },
  {
    path: "/digit",
    component: () => import("@/views/digit/index.vue"),
    redirect: "/digit/detail",
    meta: {
      title: "数字农业",
      hidden: true,
      keepAlive: true,
    },
    children: [
      {
        path: "detail",
        component: () => import("@/views/digit/detail/index.vue"),
        meta: {
          title: "详情",
          hidden: true,
          keepAlive: true,
        },
      },
      {
        path: "vtour",
        component: () => import("@/views/digit/vtour/index.vue"),
        meta: {
          title: "VR",
          hidden: true,
          keepAlive: true,
          query: { id: 1 },
        },
      },
    ],
  },
  {
    path: "/nurse",
    component: () => import("@/views/nurse/index.vue"),
    meta: {
      title: "建后管护",
      hidden: true,
      keepAlive: true,
    },
  },
  {
    path: "/application",
    component: () => import("@/views/application/index.vue"),
    // redirect: "/system/user",
    meta: {
      title: "应用系统",
      hidden: true,
      keepAlive: true,
    },
  },
  {
    path: "/401",
    component: () => import("@/views/error-page/401.vue"),
    meta: { hidden: true },
  },
  {
    path: "/404",
    component: () => import("@/views/error-page/404.vue"),
    meta: { hidden: true },
  },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes as RouteRecordRaw[],
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/construct" });
}

export default router;
